package Java7_Concurrency_Cookbook.thread_executor_framework.cached_thread_pool;

import java.util.Date;
import java.util.Random;
import java.util.concurrent.TimeUnit;

/**
 * @author lixiangke
 * @date 2017/11/17
 */
public class Task implements Runnable {
    private Date initDate;
    private String name;

    public Task(String name) {
        this.initDate = new Date();
        this.name = name;
    }

    @Override
    public void run() {
        String tName = Thread.currentThread().getName();
        try {
            //System.out.printf("%s: Zoom %s: Created on: %s\n", tName, name, initDate);
            //System.out.printf("%s: Zoom %s: Created on: %s\n", tName, name, new Date());
            Long duration = (long) new Random().nextInt(10);
            //System.out.printf("%s: Zoom %s: Doing a task during %d seconds\n", tName, name, duration);
            TimeUnit.SECONDS.sleep(duration);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.printf("%s: Zoom %s: Finished on: %s\n", tName, name, new Date());
    }
}
